package com.hjj.springboot.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hjj.springboot.config.LogType;
import com.hjj.springboot.config.SystemLogs;
import com.hjj.springboot.entity.R;
import com.hjj.springboot.entity.TalkDetail;
import com.hjj.springboot.entity.WxUserInfo;
import com.hjj.springboot.service.ITalkDetailService;
import com.hjj.springboot.service.IWxUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/talkDetail")
public class AdminTalkDetailController {

    @Autowired
    private ITalkDetailService talkDetailService;

    @Autowired
    private IWxUserInfoService wxUserInfoService;

    @GetMapping("/list/{id}")
    public R list(@PathVariable("id") Integer id) {
        List<TalkDetail>  talkDetailList = talkDetailService.list(new QueryWrapper<TalkDetail>().eq("mid",id).orderByAsc("id"));
        for (TalkDetail talkDetail : talkDetailList) {
            talkDetail.setWxUserInfo(wxUserInfoService.getOne(new QueryWrapper<WxUserInfo>().eq("openid", talkDetail.getUid())));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("list",talkDetailList);
        return R.ok(map);
    }

    @SystemLogs(operation = "论坛留言详情",type = LogType.DELETE)
    @GetMapping("/delete/{id}")
    public R delete(@PathVariable("id") Integer id) {
        talkDetailService.removeById(id);
        return R.ok();
    }

}
